import requests
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView


class WeiboView(APIView):
    def get(self, request):
        code = request.GET.get("code")
        print('远程修改7777777777')
        print('本地修改9999999999')

        print('远程修改11111111')
        print('本地修改66666666')

        # 通过python进行网络请求
        r = requests.post("https://api.weibo.com/oauth2/access_token", {
            "client_id": 1614821177,
            "client_secret": "2c0940aab8573fe729d40d59477f4db8",
            "grant_type": "authorization_code",
            "code": code,
            "redirect_uri": "http://127.0.0.1:8000/weibo",
        })
        print(r.json())
        access_token = r.json()["access_token"]
        uid = r.json()["uid"]
        return Response({'data': r.json()})
